package com.example.jinyu.protocol;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.example.jinyu.application.MainApplication;
import com.example.jinyu.entry.BaseEntity;
import com.example.jinyu.entry.BlogInfos;
import com.example.jinyu.entry.CommentInfos;
import com.example.jinyu.entry.CommentSaveInfo;
import com.example.jinyu.entry.MerchantInfos;
import com.example.jinyu.entry.MyRepairInfos;
import com.example.jinyu.entry.NoticeInfos;
import com.example.jinyu.entry.PriseInfos;
import com.example.jinyu.entry.ProductInfos;
import com.example.jinyu.entry.RentInfos;
import com.example.jinyu.entry.UnityInfos;
import com.example.jinyu.entry.UserInfos;
import com.example.jinyu.protocol.model.BlogDeleteRequest;
import com.example.jinyu.protocol.model.BlogSaveRequest;
import com.example.jinyu.protocol.model.BlogSelectRequest;
import com.example.jinyu.protocol.model.CommentSaveRequest;
import com.example.jinyu.protocol.model.CommentSelectRequest;
import com.example.jinyu.protocol.model.GetMyRepairRequest;
import com.example.jinyu.protocol.model.GoodsDeleteRequest;
import com.example.jinyu.protocol.model.GoodsSaveRequest;
import com.example.jinyu.protocol.model.GrouppicsRequest;
import com.example.jinyu.protocol.model.NoticeSelectRequest;
import com.example.jinyu.protocol.model.PriseDeleteRequest;
import com.example.jinyu.protocol.model.PriseSaveRequest;
import com.example.jinyu.protocol.model.RentSelectRequest;
import com.example.jinyu.protocol.model.ReportRepairsRequest;
import com.example.jinyu.protocol.model.SelectByStoreIdAndTypeRequest;
import com.example.jinyu.protocol.model.SelectMySelfBlogRequest;
import com.example.jinyu.protocol.model.SelectStoressByTypeRequest;
import com.example.jinyu.protocol.model.UserSelectRequest;

public class MoccaApiImpl implements MoccaApi {
    RequestQueue queue = MainApplication.get().getRequestQueue();

    private String getBaseUrl(String action) {
        return BASEURL + action;
    }

    @Override
    public Request<?> selectStoressByType(int type, int start, int end,
            Listener<MerchantInfos> listener, ErrorListener errorListener) {
        SelectStoressByTypeRequest request =
                new SelectStoressByTypeRequest(getBaseUrl(ACTION_STORESS_SELECT), listener,
                        errorListener);
        request.addParams(PARAM_TYPE, type);
        request.addParams(PARAM_START, start);
        request.addParams(PARAM_END, end);
        return queue.add(request);
    }

    @Override
    public Request<?> noticeSelect(long id, int start, int end, Listener<NoticeInfos> listener,
            ErrorListener errorListener) {
        NoticeSelectRequest request =
                new NoticeSelectRequest(getBaseUrl(ACTION_NOTICE_SELECT), listener, errorListener);
        request.addParams(PARAM_ID, id);
        request.addParams(PARAM_START, start);
        request.addParams(PARAM_END, end);
        return queue.add(request);
    }

    @Override
    public Request<?> rentSelect(String id, int start, int end, Listener<RentInfos> listener,
            ErrorListener errorListener) {
        RentSelectRequest request =
                new RentSelectRequest(getBaseUrl(ACTION_RENT_SELECT), listener, errorListener);
        request.addParams(PARAM_ID, id);
        request.addParams(PARAM_START, start);
        request.addParams(PARAM_END, end);
        return queue.add(request);
    }

    @Override
    public Request<?> selectByStoreIdAndType(int type, String storeId, int start, int end,
            Listener<ProductInfos> listener, ErrorListener errorListener) {
        SelectByStoreIdAndTypeRequest request =
                new SelectByStoreIdAndTypeRequest(getBaseUrl(ACTION_GOODS_SELECTBYSTOREIDANDTYPE),
                        listener, errorListener);
        request.addParams(PARAM_TYPE, type);
        request.addParams(PARAM_STOREID, storeId);
        request.addParams(PARAM_START, start);
        request.addParams(PARAM_END, end);
        return queue.add(request);
    }

    @Override
    public Request<?> userSelect(String id, int start, int end, Listener<UserInfos> listener,
            ErrorListener errorListener) {
        UserSelectRequest request =
                new UserSelectRequest(getBaseUrl(ACTION_USER_SELECT), listener, errorListener);
        request.addParams(PARAM_ID, id);
        request.addParams(PARAM_START, start);
        request.addParams(PARAM_END, end);
        return queue.add(request);
    }

    @Override
    public Request<?> goodsSave(String goods, Listener<UnityInfos> listener,
            ErrorListener errorListener) {
        GoodsSaveRequest request =
                new GoodsSaveRequest(getBaseUrl(ACTION_GOODSSAVE), listener, errorListener);
        request.addParams(PARAM_GOODS, goods);
        return queue.add(request);
    }

    @Override
    public Request<?> goodsDelete(String goods, Listener<Boolean> listener,
            ErrorListener errorListener) {
        GoodsDeleteRequest request =
                new GoodsDeleteRequest(getBaseUrl(ACTION_GOODSDELETE), listener, errorListener);
        request.addParams(PARAM_GOODS, goods);
        return queue.add(request);
    }

    @Override
    public Request<?> reportRepairs(String repair, Listener<BaseEntity> listener,
            ErrorListener errorListener) {
        ReportRepairsRequest request =
                new ReportRepairsRequest(getBaseUrl(ACTION_COMMONREPORTREPAIRS), listener,
                        errorListener);
        request.addParams(PARAM_REPAIR, repair);
        return queue.add(request);
    }

    @Override
    public Request<?> getMyRepair(long userid, int start, int end,
            Listener<MyRepairInfos> listener, ErrorListener errorListener) {
        GetMyRepairRequest request =
                new GetMyRepairRequest(getBaseUrl(ACTION_COMMONGETMYREPAIR), listener,
                        errorListener);
        request.addParams(PARAM_USERID, userid);
        request.addParams(PARAM_START, start);
        request.addParams(PARAM_END, end);
        return queue.add(request);
    }

    @Override
    public Request<?> blogSave(String blog, Listener<BaseEntity> listener,
            ErrorListener errorListener) {
        BlogSaveRequest request =
                new BlogSaveRequest(getBaseUrl(ACTION_BLOGSAVE), listener, errorListener);
        request.addParams(PARAM_BLOG, blog);
        return queue.add(request);
    }

    @Override
    public Request<?> blogDelete(String blog, Listener<BaseEntity> listener,
            ErrorListener errorListener) {
        BlogDeleteRequest request =
                new BlogDeleteRequest(getBaseUrl(ACTION_BLOGDELETE), listener, errorListener);
        request.addParams(PARAM_BLOG, blog);
        return queue.add(request);
    }

    @Override
    public Request<?> blogSelect(long id, String navigation, Listener<BlogInfos> listener,
            ErrorListener errorListener) {
        BlogSelectRequest request =
                new BlogSelectRequest(getBaseUrl(ACTION_BLOGSELECT), listener, errorListener);
        request.addParams(PARAM_ID, id);
        // request.addParams(PARAM_START, start);
        // request.addParams(PARAM_END, end);
        request.addParams(PARAM_NAVIGATION, navigation);
        return queue.add(request);
    }

    @Override
    public Request<?> selectMySelfBlog(long userid, String navigation,
            Listener<BlogInfos> listener, ErrorListener errorListener) {
        SelectMySelfBlogRequest request =
                new SelectMySelfBlogRequest(getBaseUrl(ACTION_BLOGSELECTMYSELFBOLOG), listener,
                        errorListener);
        request.addParams(PARAM_USERID_, userid);
        request.addParams(PARAM_NAVIGATION, navigation);
        return queue.add(request);
    }

    @Override
    public Request<?> commentSave(String comment, Listener<CommentSaveInfo> listener,
            ErrorListener errorListener) {
        CommentSaveRequest request =
                new CommentSaveRequest(getBaseUrl(ACTION_COMMENTSAVE), listener, errorListener);
        request.addParams(PARAM_COMMENT, comment);
        return queue.add(request);
    }

    @Override
    public Request<?> priseSave(String prise, Listener<PriseInfos> listener,
            ErrorListener errorListener) {
        PriseSaveRequest request =
                new PriseSaveRequest(getBaseUrl(ACTION_PRISESAVE), listener, errorListener);
        request.addParams(PARAM_PRISE, prise);
        return queue.add(request);
    }

    @Override
    public Request<?> priseDelete(String prise, Listener<PriseInfos> listener,
            ErrorListener errorListener) {
        PriseDeleteRequest request =
                new PriseDeleteRequest(getBaseUrl(ACTION_PRISEDELETE), listener, errorListener);
        request.addParams(PARAM_PRISE, prise);
        return queue.add(request);
    }

    @Override
    public Request<?> commentSelect(String id, String navigation, Listener<CommentInfos> listener,
            ErrorListener errorListener) {
        CommentSelectRequest request =
                new CommentSelectRequest(getBaseUrl(ACTION_COMMENT_SELECT), listener, errorListener);
        request.addParams(PARAM_ID, id);
        request.addParams(PARAM_NAVIGATION, navigation);
        return queue.add(request);
    }

    @Override
    public Request<?> grouppics(String grouppics, Listener<BaseEntity> listener,
            ErrorListener errorListener) {
        GrouppicsRequest request =
                new GrouppicsRequest(getBaseUrl(ACTION_GROUPPICSSAVE), listener, errorListener);
        request.addParams("grouppics", grouppics);
        return queue.add(request);
    }

}
